/*
 * ContactBookServiceImpl.java
 *
 * Created on October 27, 2008, 10:04 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.vacuela.publishmx.services;

import java.util.List;
import org.vacuela.publishmx.context.ServiceContext;
import org.vacuela.publishmx.domains.Contact;
import org.vacuela.publishmx.domains.ContactNumber;
import org.vacuela.publishmx.domains.Group;

/**
 *
 * @author nestor.carrasco
 */
public class ContactBookServiceImpl  extends AbstractDaoBasedPublish implements ContactBookService{
    
    /** Creates a new instance of ContactBookServiceImpl */
    public ContactBookServiceImpl() {
    }

    public void saveUpdateGroup(ServiceContext context) {
        Group group = (Group)context.getAttribute("groupDomain");
        groupDao.saveUpdate(group);
    }

    public void getGroupsByUserId(ServiceContext context) {
        Integer userId = (Integer)context.getAttribute("userId");
        List<Group>  myGroupList =(List<Group>) this.groupDao.getGroupByUserId(userId);
        context.setAttribute("groupList",myGroupList );
    }

    public void getGroupList(ServiceContext context) {
    }

    public void getGroupById(ServiceContext context) {
        Group group = (Group) context.getAttribute("groupDomain");
        group = groupDao.getGroup(group);
        context.setAttribute("group", group);
    }
    

    public void searchGroupByName(ServiceContext context) {
    }

    public void deleteGroup(ServiceContext context) {
        Integer groupId = (Integer)context.getAttribute("groupId");
        boolean status = groupDao.deleteGroup(groupId);
        context.setAttribute("status",status);
    }
    
    public void saveUpdateContact(ServiceContext context) {
         Contact contact = (Contact)context.getAttribute("contactDomain");
         this.contactDao.saveUpdate(contact);
    }
    

    public void getContactByUserId(ServiceContext context) {
    }

    public void getContactByGroupId(ServiceContext context) {
        Integer gId = new Integer((String)context.getAttribute("groupId"));
        List<Contact> lstContact = ( List<Contact>) this.contactDao.getContactByGroupId(gId);
        context.setAttribute("lstContact", lstContact);
    }

    public void getContactList(ServiceContext context) {
    }

    public void getContactById(ServiceContext context) {
      //  Integer cId = new Integer((String)context.getAttribute("contactDomain"));
        Contact contact = (Contact)context.getAttribute("contactDomain");
        contact =   this.contactDao.getContact(contact.getId());
        context.setAttribute("contact", contact);
    }

    public void searchContactByName(ServiceContext context) {
    }

    public void deleteContact(ServiceContext context) {
    }
    
    public void  getPhoneNumbers(ServiceContext context){
        String[] contactIdSelected = (String[])context.getAttribute("contactIdSelected");
        List<ContactNumber> lstPhones = (List<ContactNumber>)this.contactDao.getPhoneNumbers(contactIdSelected);
        context.setAttribute("phoneNumbersLst", lstPhones);
    }
}
